package hlhj.fhp.newslib.activitys

import android.support.v7.widget.LinearLayoutManager
import com.bumptech.glide.Glide
import com.lzy.okgo.model.Response
import hlhj.fhp.newslib.BaseAty
import hlhj.fhp.newslib.R
import hlhj.fhp.newslib.adapters.SpecialMultiAdp
import hlhj.fhp.newslib.adapters.SpecialSingleAdp
import hlhj.fhp.newslib.javabean.SpecialDetailBean
import hlhj.fhp.newslib.network.Apis
import hlhj.fhp.newslib.network.CustomAction
import hlhj.fhp.newslib.network.LoadingAction
import hlhj.fhp.newslib.network.Urls
import hlhj.fhp.newslib.utils.GlideUtil
import kotlinx.android.synthetic.main.aty_news_special_detail.*
import kotlinx.android.synthetic.main.hlhj_news_list_lo.*

/**
 * Created by Administrator on 2018\6\25 0025.
 */
class SpecialDetailAty :BaseAty() {
    private lateinit var adp : SpecialMultiAdp
    private val datas=ArrayList<SpecialDetailBean.DataBean.ListBean>()
    private var page=1;

    override fun initListener() {
        btExit.setOnClickListener {
            finish()
        }
    }
    override fun initView() {
        tvTittle.text=intent.getStringExtra("tittle")
        /*适配器*/
        /*上下拉框架*/
//        spView.setListener(this)
        /*列表*/

        adp= SpecialMultiAdp(datas)

        recyclerview.layoutManager= LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false)
        recyclerview.adapter=adp
        disPatchData()
    }

    private fun disPatchData() {
        Apis.getSpecialDetail(intent.getIntExtra("id",0))
                .doOnSubscribe(LoadingAction(this))
                .subscribe(object :CustomAction<Response<SpecialDetailBean>>{
                    override fun onResult(t: Response<SpecialDetailBean>) {
                        loadingDialog.dismiss()
                        val detailBean = t.body()
                        if (null!=detailBean.data.list){
                            datas.addAll(detailBean.data.list)
                            adp.notifyDataSetChanged()
                        }
                        if (detailBean.data.cover_img.contains("http")){
                            Glide.with(this@SpecialDetailAty).load(detailBean.data.cover_img)
                                    .apply(GlideUtil.loadIMGOption())
                                    .into(headImg)
                        }else{
                            Glide.with(this@SpecialDetailAty).load(Urls.Base_URL+"/"+detailBean.data.cover_img)
                                    .apply(GlideUtil.loadIMGOption())
                                    .into(headImg)
                        }

                    }
                })
    }

    override fun getContentId(): Int {
        return R.layout.aty_news_special_detail
    }
}